<template>
    <div class="screen">
      <mt-header title="找回密码" class="title">
        <router-link to="/login" slot="left">
          <mt-button icon="back"></mt-button>
        </router-link>
      </mt-header>
      <div class="bigInterval">
        <div id="star_tips"><span class="star_tips_span">*</span><span>输入丢失账号绑定的手机号</span></div>
      </div>
      <form>
        <mt-field label="手机号" placeholder="请输入手机号" type="tel" v-model="phoneNumber"></mt-field>
        <div class="littleInterval"></div>
        <mt-button type="default" size="large" @click.native="nextStep">下一步</mt-button>
      </form>
      <div>
        <p id="footer_tips">
          <span class="star_tips_span">*</span>
          <span>如遇到问题，咨询客服：<span class="phonecss">400-123-1234</span></span>
        </p>
      </div>
    </div>

</template>

<script>
  import { Toast } from 'mint-ui';
  import axios from 'axios'
    export default {
        name: "ForgetPassword",
      data(){
          return{
            phoneNumber:''
          }
      },
      methods:{
          nextStep(){
            if(this.phoneNumber.trim()==""){
              Toast('手机号码不能为空!');
              return;
            }
            if(this.$route.params.type==0){
              axios.post("/api/sUser/listAll",{conditions: {'phone_eq': this.phoneNumber}}).then(res=>{
                console.log(res);
                if(res.data.data.length==0){
                  Toast('不存在此企业用户！');
                }else if(res.data.data.length==1){
                  this.$router.push({path:'changePassword',params:{
                      phone:this.phoneNumber,
                      type:0
                    }});
                }else{
                  Toast('此账号存在问题，请联系客服！');
                }
              });
            }else{
              axios.post("/api/eUser/listAll",{conditions: {'phone_eq': this.phoneNumber}}).then(res=>{
                console.log(res);
                if(res.data.data.length==0){
                  Toast('不存在此企业用户！');
                  return;
                }else if(res.data.data.length==1){
                  this.$router.push({path:'changePassword',params:{
                      phone:this.phoneNumber,
                      type:1
                    }});
                }else{
                  Toast('此账号存在问题，请联系客服！');
                  return;
                }
              });
            }
          }
        }
    }
</script>

<style scoped>
  .bigInterval{
    height: 4rem;
    background-color: rgba(169, 169, 169, 0.08);
  }
  #star_tips{
    height: 4rem;
    text-align: left;
    padding-left: 1rem;
    line-height: 4;
  }
  .star_tips_span{
    color: red;
    margin-right: 1rem;
  }
  #footer_tips{
    margin-top: 1rem;
  }
  .phonecss{
    color: dodgerblue;
  }
</style>
